package com.pucheng.bracelet.ui.fragment.steps

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.ext.KEY_DATE
import com.pucheng.bracelet.viewmodel.steps.StepsToDayViewModel
import kotlinx.android.synthetic.main.fragment_steps_to_day.*
import me.hgj.jetpackmvvm.base.fragment.BaseVmFragment
import com.pucheng.bracelet.app.util.DatetimeUtil
import com.pucheng.bracelet.viewmodel.steps.StepsViewModel

class StepsToDayFragment : BaseVmFragment<StepsToDayViewModel>() {
    val stepsViewModel by activityViewModels<StepsViewModel>()
    override fun createObserver() {
        stepsViewModel.apply {
            stepsData.observe(viewLifecycleOwner, Observer {
                if (it != null) {
                    tv_steps_num.text = it.stepsNum + getString(R.string.steps2)
                    tv_steps_updata_date.text = DatetimeUtil.formatDate(
                        DatetimeUtil.formatDate(
                            DatetimeUtil.DATE_PATTERN_EE,it.date), DatetimeUtil.DATE_PATTERN_EE)
                }
            })
        }
    }

    override fun dismissLoading() {
    }

    override fun initView(savedInstanceState: Bundle?) {
//        mViewModel.queryDateToDate()
    }

    override fun layoutId(): Int = R.layout.fragment_steps_to_day

    override fun lazyLoadData() {
    }

    override fun showLoading(message: String) {
    }

    companion object {
        fun newInstance(): StepsToDayFragment {
            val fragment = StepsToDayFragment()
            return fragment
        }
    }

//    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
//        super.onActivityResult(requestCode, resultCode, data)
//        mViewModel.queryDate.value = data!!.getStringExtra(KEY_DATE)
//        mViewModel.queryDateToDate()
//    }
}